package com.nineclock.sign.controller;


import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignInfoDTO;
import com.nineclock.sign.dto.SignListDTO;
import com.nineclock.sign.dto.SignReportFormsDTO;
import com.nineclock.sign.pojo.SignInfo;
import com.nineclock.sign.service.SignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@Api(value = "签到服务接口与管理", tags = "签到服务")
@RestController
@RequestMapping

public class SignController {

    @Autowired
    private SignService signService;


    /**
     * 接口名称：APP: 签到
     * 接口路径：POST/sign/insert
     */
    @PostMapping("insert")
    @ApiOperation("APP: 签到")
    public Result signIn(@RequestParam Map<String, String> map) {
        String visit = map.get("visit");
        String address = map.get("remark");
        String lat = map.get("lat");
        String lng = map.get("lng");
        String remark = map.get("remark");
        String images = map.get("images");
        String imei = map.get("imei");

        SignInfoDTO signInfoDTO = new SignInfoDTO(new BigDecimal(lat), new BigDecimal(lng), address, remark, visit, imei, images);

        signService.toSign(signInfoDTO);

        return Result.success();
    }

    /**
     * 接口名称：APP: 查询本月签到记录
     * 接口路径：GET/sign/pagingSignCurrentUserByMonth
     */
    @GetMapping("pagingSignCurrentUserByMonth")
    @ApiOperation("APP: 查询本月签到记录")
    public Result<List<SignInfoDTO>> querySignCurrentUserByMonth(@RequestParam String dateStr) {
        List<SignInfoDTO> signInfoDTOList = signService.querySignCurrentUserByMonth(dateStr);
        return Result.success(signInfoDTOList);
    }


    //APP: 获取当前用户当天签到次数
    //接口路径：GET/sign/getDayCount
    @GetMapping("/getDayCount")
    public Result<Integer> getDayCount() {

        Integer dayCount = signService.getDayCount();
        return Result.success(dayCount);
    }


    /**
     * PC: 查询签到列表
     * 接口路径：GET/sign/sign
     */
    @ApiOperation("PC: 查询签到列表")
    @GetMapping("sign")
    public Result<PageResult<SignReportFormsDTO>> querySignReportForms(@RequestParam String endTime,
                                                                       @RequestParam(defaultValue = "1") Integer page,
                                                                       @RequestParam(defaultValue = "5") Integer pageSize,
                                                                       @RequestParam String startTime) {
        PageResult<SignReportFormsDTO> signReportFormsPageResult = signService.querySignReportForms(endTime, page, pageSize, startTime);
        return Result.success(signReportFormsPageResult);
    }

    /**
     * PC: 导出签到列表
     * 接口路径：GET/sign/export
     */
    @ApiOperation("PC: 导出签到列表")
    @GetMapping("export")
    public void exportSignData(String endTime, String startTime) throws IOException {
        signService.exportSignData(startTime, endTime);
    }

    /**
     * APP: 获取团队员工打卡列
     * 接口路径：GET/sign/listSignAllUser
     */
    @GetMapping("listSignAllUser")
    @ApiOperation("APP: 获取团队员工打卡列表")
    public Result<List<SignListDTO>> listSignAllUser(@RequestParam String dateStr){
        List<SignListDTO> signListDTOList=signService.listSignAllUser(dateStr);
        return Result.success(signListDTOList);
    }

}
